<template>
  <a-space>
    <a-button v-if="isLogin()" @click="logout">
      <span style="margin-right: 12px;">
        退出
      </span>
      <icon-export />
    </a-button>
    <a-button v-else @click="$router.push({ name: 'login' })">
      <span>
        登录
      </span>
    </a-button>
  </a-space>

</template>

<script setup>
import { isLogin, token } from '@/stores/token'
import { useRouter } from 'vue-router';

const props = defineProps({
  redirectToLogin: {
    type: Boolean,
    value: true,
  }
})

const router = useRouter()

const logout = () => {
  token.value = undefined
  if (props.redirectToLogin) {
    router.push({ name: 'login' })
  }
}
</script>

<style lang="css" scoped></style>
